<template>
  <!--  -->
  <el-tree
    ref="deptsTree"
    :data="depts"
    node-key="id"
    :props="{label: 'name'}"
    default-expand-all
    :expand-on-click-node="false"
    highlight-current
    @current-change="selextNode"
  />
</template>

<script>
import { getDepartmentsAPI } from '@/api/department'
import { transListToTreeData } from '@/utils'
export default {
  props: {

  },
  data() {
    return {
      depts: [],
      queryParmas: {

        keyword: '',
        departmentId: null
      }
    }
  },
  created() {
    this.getdeptsData()
  },
  methods: {
    selextNode(nodeData) {
      // 切换默认显示第一页
      this.queryParmas.departmentId = nodeData.id
      // console.log(nodeData)
      this.$emit('select', nodeData.id)
    },
    async getdeptsData() {
      // 获取部门列表
      this.depts = transListToTreeData(await getDepartmentsAPI(), 0)
      this.queryParmas.departmentId = this.depts[0].id
      this.$nextTick(() => {
        this.$refs.deptsTree.setCurrentKey(this.depts[0].id)
      })
    }
  }
}
</script>

<style>

</style>
